from rest_framework import serializers

from goods.models import SPU,Brand,GoodsCategory


# class SubsSerializer(serializers.ModelSerializer):
#
#     class Meta:
#         model = GoodsCategory
#         fileds = "__all__"


class CategoriesSerializer(serializers.ModelSerializer):
    """一级商品"""
    # name = serializers.StringRelatedField(read_only=True,required=None)

    class Meta:
        model = GoodsCategory
        fields = "__all__"


class BrandSerializer(serializers.ModelSerializer):
    """品牌序列化器"""
    # name = serializers.StringRelatedField()

    class Meta:
        model = Brand
        fields = "__all__"


class SPUSerializer(serializers.ModelSerializer):
    """商品序列化器"""
    brand = serializers.StringRelatedField()
    brand_id = serializers.IntegerField()
    # 使用related_name不能实现效果，不涉及嵌套返回应该用不到
    category1_id = serializers.StringRelatedField()
    category2_id = serializers.StringRelatedField()
    category3_id = serializers.StringRelatedField()

    class Meta:
        model = SPU
        fields = "__all__"
